cmake_minimum_required(VERSION 3.10)
project(server CXX C)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(CMAKE_C_FLAGS_DEBUG " -std=c11 -g -ggdb -O0 -Wall -Wno-unused-function -fpic -fPIC -D_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG " -std=c++11 -g -ggdb -O0 -Wall -Wno-unused-function -fpic -fPIC -D_DEBUG")

set(CMAKE_C_FLAGS_RELEASE " -std=c11 -O3 -Wall -Wno-unused-function -fpic -fPIC")
set(CMAKE_CXX_FLAGS_RELEASE " -std=c++11 -O3 -Wall -Wno-unused-function -fpic -fPIC")

# Find Protobuf installation
# Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
option(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")

# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")

include_directories(
    # /include    # 这里替换成gRPC的编译安装目录下的include
    # include
    ${CMAKE_CURRENT_SOURCE_DIR}/../generated/ # 这里是通过protoc生成的文件存放的目录有.h
    )
link_directories(
    /lib64     # 这里替换成gRPC的编译安装目录下的lib64
    lib
    )

aux_source_directory(src SRC_LIST)
aux_source_directory(../generated/ PROTOBUF_SRC_LIST) # 这里是通过protoc生成的文件存放的目录有.cc
add_executable(${PROJECT_NAME}
    ${SRC_LIST}
    ${PROTOBUF_SRC_LIST}
    )

target_link_libraries(${PROJECT_NAME}
    pthread
    absl::flags
    absl::flags_parse
    protobuf::libprotobuf
    gRPC::grpc++_reflection
    gRPC::grpc++
    )